﻿using System;
using System.Collections.Generic;
using NRFramework;

namespace Gp.Scripts.Core
{
    public class UIConfigInfo
    {
        public string Id;
        public string PrefabPath;
        public Type ClassType;
        public UIPanelLayer PanelLayer;
    }
    
    public abstract class UISystemConfig : SystemSystemConfig
    {
        private Dictionary<string, UIConfigInfo> _panelMap;
        private Dictionary<string, UIConfigInfo> _widgetMap;
        
        
        protected override void OnLoad()
        {
            _panelMap   = new Dictionary<string, UIConfigInfo>();
            _widgetMap  = new Dictionary<string, UIConfigInfo>();
            LoadConfigs();
        }
        
        public void AddPanel<T>(string panelId, UIPanelLayer panelLayer) where T : UIPanel
        {
            _panelMap.Add(panelId, new UIConfigInfo { Id = panelId, PrefabPath = panelId, ClassType =  typeof(T), PanelLayer = panelLayer});
        }

        public void AddPanel<T>(string panelId, string prefabPath, UIPanelLayer panelLayer) where T : UIPanel
        {
            _panelMap.Add(panelId, new UIConfigInfo { Id = panelId, PrefabPath = prefabPath, ClassType =  typeof(T), PanelLayer = panelLayer});
        }
        

        // public void AddWidget<T>(string widgetId, UIPanelLayer panelLayer) where T : UIWidget
        // {
        //     _widgetMap.Add(widgetId, new UIConfigInfo() { Id = widgetId, PrefabName = widgetId, ClassType =  typeof(T)});
        // }
        
        
        public UIConfigInfo GetPanelInfo(string panelId)
        {
            return _panelMap[panelId];
        }
        //
        // public string GetWidgetInfo<T>() where T : UIPanel
        // {
        //     return _widgetMap.GetValueOrDefault(typeof(T));
        // }


        protected abstract void LoadConfigs();
    }
}